package net.learn.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.learn.framework.common.page.PageResult;
import net.learn.framework.common.service.impl.BaseServiceImpl;
import net.learn.system.convert.SysMyExamConvert;
import net.learn.system.convert.SysMyPaperConvert;
import net.learn.system.dao.SysMyExamDao;
import net.learn.system.entity.SysMyExamEntity;
import net.learn.system.entity.SysMyPaperEntity;
import net.learn.system.query.SysMyExamQuery;
import net.learn.system.query.SysMyPaperQuery;
import net.learn.system.service.SysMyExamService;
import net.learn.system.utils.UUIDUtil;
import net.learn.system.vo.SysMyExamVO;
import net.learn.system.vo.SysMyPaperVO;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 */
@Service
public class SysMyExamServiceImpl extends BaseServiceImpl<SysMyExamDao, SysMyExamEntity> implements SysMyExamService {
    @Override
    public String addMyExam(SysMyExamVO vo){
        SysMyExamEntity entity = SysMyExamConvert.INSTANCE.convert(vo);
        String uuid= UUIDUtil.uuid();
        entity.setUid(uuid);
        baseMapper.insert(entity);
        return uuid;
    }
    @Override
    public Boolean updateMyExam(SysMyExamVO vo){
        SysMyExamEntity entity = SysMyExamConvert.INSTANCE.convert(vo);
        return baseMapper.updateById(entity) > 0;
    }
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delete(List<Long> idList) {

        removeByIds(idList);
    }

    @Override
    public List<SysMyExamVO> qryMyExamQuestionList(SysMyExamQuery qry) {

        return baseMapper.qryMyExamQuestionList(qry);
    }
    @Override
    public List<SysMyExamVO> qryMyExamScoreList(SysMyExamQuery qry) {

        return baseMapper.qryMyExamQuestionList(qry);
    }
    @Override
    public PageResult<SysMyExamVO> qryMyExamListPage(SysMyExamQuery query) {
        IPage<SysMyExamEntity> page = baseMapper.qryExamListPage(getPage(query), query);

        return new PageResult<>(SysMyExamConvert.INSTANCE.convertList(page.getRecords()), page.getTotal());
    }
}
